<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var list = [51, 24, 76, 66, 39, 48, 11];

    function quickSort(list) {

        if (list.length == 0 || list.length == 1) {
            return list;
        }

        var midIndex = Math.floor(list.length / 2);
        var midItem = list.splice(midIndex, 1)[0];  // 被删除的元素形成的新数组 -> 并对数组取值(去除被删除的元素)
        console.log(midItem, list);

        var leftArr = [];
        var rightArr = [];
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            if (item <= midItem) {
                leftArr.push(item);
            } else {
                rightArr.push(item);
            }
        }

        // console.log(leftArr, midItem, rightArr);

        var leftRes = quickSort(leftArr);
        var RightRes = quickSort(rightArr);

        return leftRes.concat(midItem, RightRes);


    }

    var result = quickSort(list);
    console.log(result);














</script>

</html>